<template>
  <el-dialog title="编辑会员等级" :visible.sync="visible" :close-on-click-modal="false" :before-close="handleCloseDialog"
    width="780px">
    <el-form :model="dataObject" :rules="rules" ref="adminForm" label-width="170px" size="small">
      <el-form-item label="会员等级(请勿修改)：" prop="level">
        <el-input v-model="dataObject.level" clearable disabled  placeholder="请输入会员等级"></el-input>
      </el-form-item>
      <el-form-item label="会员价格：" prop="price">
        <el-input v-model="dataObject.price" clearable  placeholder="请输入会员价格"></el-input>
      </el-form-item>
      <el-form-item label="接单限制：" prop="orderLimit">
        <el-input v-model="dataObject.orderLimit" clearable  placeholder="请输入接单限制"></el-input>
      </el-form-item>
      <el-form-item label="佣金比例：" prop="rebateRatio">
        <el-input v-model="dataObject.rebateRatio" clearable  placeholder="请输入佣金比例"></el-input>
      </el-form-item>
      <!-- <el-form-item label="提现次数：" prop="withdrawNum">
        <el-input v-model="dataObject.withdrawNum" clearable></el-input>
      </el-form-item> -->
      <el-form-item label="提现最小限制：" prop="withdrawMin">
        <el-input v-model="dataObject.withdrawMin" clearable  placeholder="请输入提现最小限制"></el-input>
      </el-form-item>
      <el-form-item label="提现最大限制：" prop="withdrawMax">
        <el-input v-model="dataObject.withdrawMax" clearable  placeholder="请输入提现最大限制"></el-input>
      </el-form-item>
      <!-- <el-form-item label="用户余额限制：" prop="balanceMin">
        <el-input v-model="dataObject.balanceMin" clearable></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="自动升级需邀请：" prop="autoVipNum">
        <el-input v-model="dataObject.autoVipNum" clearable></el-input>
      </el-form-item>
      <el-form-item label="提现至少完成订单/天：" prop="withdrawMinOrder">
        <el-input v-model="dataObject.withdrawMinOrder" clearable></el-input>
      </el-form-item> -->
      <el-form-item label="提现手续费：" prop="withdrawRate">
        <el-input v-model="dataObject.withdrawRate" clearable  placeholder="请输入提现手续费"></el-input>
      </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleConfirmDialog('adminForm')" size="mini">确 定</el-button>
      <el-button @click="handleCloseDialog" size="mini">取 消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { updataMemberLeve } from '@/api/member/index';
import { createNamespacedHelpers } from "vuex";
const { mapState } = createNamespacedHelpers("member");

const defaultObject = {
  level: "",
  price: "",
  orderLimit: '',
  rebateRatio: '',
  withdrawNum: "",
  withdrawMin: '',
  withdrawMax: '',
  balanceMin: '',
  autoVipNum: '',
  withdrawMinOrder: "",
  withdrawRate: ''
};

export default {
  name: "editGradeDialog",
  data() {
    return {
      loading: false,
      dataObject: Object.assign({}, defaultObject),
      visible: true
    };
  },
  props: {
    row: {
      type: Object,
      default: {}
    }
  },
  computed: {
    ...mapState({
      rules: state => state.rules
    })
  },
  mounted() {
    this.dataObject = {...this.dataObject, ...this.row};
  },
  methods: {
    handleCloseDialog() {
      this.$emit("handle-cancel");
    },
    handleConfirmDialog(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          updataMemberLeve({...this.dataObject,id:this.row.id}).then(response => {
            this.resetForm(formName);
            this.$message({
              message: "修改成功",
              type: "success",
              duration: 1000
            });
            this.$emit("handle-confirm");
          });
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dataObject = Object.assign({}, defaultObject);
    }
  }
};
</script>
<style scoped>

</style>